package com.frxuexi.shop.viewmodel

import com.frxuexi.lib_base.http.RequestType
import com.frxuexi.lib_base.http.ShopApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.shop.intent.CartIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class CartViewModel @Inject constructor(val apiService: ShopApiService):BaseViewModel<CartIntent>(){
    override fun handleIntent(it: CartIntent) {
        when(it){
            is CartIntent.getCarts->httpRequest(apiService.getCarts(it.page))
            is CartIntent.updateCart->httpRequest(apiService.updateCart(it.id,it.num),RequestType.UPDATE)
            is CartIntent.deleteCart->httpRequest(apiService.deleteCart(it.ids),RequestType.DELETE)
            is CartIntent.preOrder->httpRequest(apiService.repreOrder(toBody(it.item)),RequestType.PREORDER)
            is CartIntent.getPreOrder->httpRequest(apiService.getPreOrder(it.preNo),RequestType.GET_PREORDER)
            is CartIntent.createOrder->httpRequest(apiService.createOrder(toBody(it.item)),RequestType.CREATE_ORDER)
        }
    }
}